package com.qzsoft.zhjd.machine.modules.stationmaintain.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.system.modules.sysstation.entity.SysStationEntity;
import com.qzsoft.system.modules.sysstation.enums.SysStationType;
import com.qzsoft.system.modules.sysstation.service.SysStationService;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.machine.modules.stationmaintain.dto.StationMaintainDto;
import com.qzsoft.zhjd.machine.modules.stationmaintain.entity.StationMaintainEntity;
import com.qzsoft.zhjd.machine.modules.stationmaintain.service.StationMaintainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
 * @ClassName StationMaintainController
 * @Description 拌合楼维修保养
 * @author zhaij
 * @since 2021-08-23
 */
@Api(tags = "拌合楼维修保养")
@RestController
@RequestMapping("/api/stationmaintain")
public class StationMaintainController {

    @Autowired
    private StationMaintainService stationMaintainService;

    @Autowired
    private SysStationService sysStationService;

    /**
     * @Title: page
     * @Description: 拌合楼维修保养
     * @return Result 拌合楼维修保养
     */
    @RequiresPermissions("materiel:cooperateunit:list")
    @ApiOperation(value = "拌合楼维修保养列表")
    @GetMapping("/page")
    public Result<IPage<StationMaintainDto>> page(@RequestParam(required = false) Map<String,Object> params) {
        IPage<StationMaintainDto> page = stationMaintainService.qryDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title list
     * @Description 获取拌合楼列表
     * @return 获取拌合楼列表
     */
    @GetMapping("/list")
    public Result<List<SysStationEntity>> list(@RequestParam Map<String,Object> params) {
        params.put("type", SysStationType.ASPHALT.getValue());
        List<SysStationEntity> list = sysStationService.list(params);
        return ResultUtils.ok(list);
    }

    /**
     * 保存或修改合作单位
     * @param params
     * @return
     */
    @RequiresPermissions("materiel:cooperateunit:save")
    @ApiOperation(value = "保存或修改拌合楼维修记录")
    @PostMapping("/saveStation")
    public Result<String> saveCooperate(@RequestBody StationMaintainEntity params) {
        ValidatorUtils.validateEntity(params);
        stationMaintainService.save(params);
        return ResultUtils.ok();
    }

    /**
     * 保存或修改合作单位
     * @param params
     * @return
     */
    @ApiOperation(value = "修改拌合楼维修记录")
    @PostMapping("/editStation")
    public Result<String> editCooperate(@RequestBody StationMaintainEntity params) {
        ValidatorUtils.validateEntity(params);
        stationMaintainService.updateById(params);
        return ResultUtils.ok();
    }

    /**
     * 删除合作单位
     * @param id
     * @return
     */
    @RequiresPermissions("materiel:cooperateunit:remove")
    @ApiOperation(value = "删除拌合楼维护记录")
    @PostMapping("/delete/{id}")
    public Result<String> deleteCooperate(@PathVariable @NotBlank(message="拌合楼维护记录id不能为空") String id) {
        stationMaintainService.removeById(id);
        return ResultUtils.ok();
    }

    /**
     * 查询合作单位详情
     * @param id
     * @return
     */
    @RequiresPermissions("materiel:cooperateunit:edit")
    @ApiOperation(value = "查询拌合楼详情")
    @GetMapping("/getDetail/{id}")
    public Result<StationMaintainEntity> getCooperate(@PathVariable("id") String id) {
        return ResultUtils.ok(stationMaintainService.getById(id));
    }

}
